package com.zkthink.ceres.member.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.zkthink.base.R;
import com.zkthink.base.service.SuperServiceImpl;
import com.zkthink.ceres.member.dao.IntegralMapper;
import com.zkthink.ceres.member.dto.IntegralSaveDTO;
import com.zkthink.ceres.member.entity.Integral;
import com.zkthink.ceres.member.service.IntegralService;
import com.zkthink.database.mybatis.conditions.Wraps;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * FileName: IntegralServiceImpl
 * Author:   Pepis
 * Date:   2020  2020/8/29 16:16
 * Description: 会员积分 实现类
 **/
@Slf4j
@Service
public class IntegralServiceImpl extends
        SuperServiceImpl<IntegralMapper, Integral> implements
        IntegralService {
    /**
     * 根据会员查询 积分记录
     *
     * @param mid 会员id
     * @return
     */
    @Override
    public List<Integral> getIntegralListByMID(Long mid) {
        return baseMapper.getIntegralListByMID(mid);
    }

    @Override
    public R<Boolean> save(IntegralSaveDTO entity) {
        if (entity.getMid() <= 0) {
            return R.fail("会员id不能为空");
        }
        Integral integral = BeanUtil.copyProperties(entity, Integral.class);
        return R.success(baseMapper.insert(integral) > 0);
    }
}
